home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.earthlink.net!usenet
- From: laserlight@earthlink.net (Lewis Burmeister)
- Newsgroups: comp.lang.c++
- Subject: Re: A simple "find the bug" (please! I need help :)
- Date: Thu, 22 Feb 1996 03:01:55 GMT
- Organization: Earthlink Network, Inc.
- Message-ID: <4ggmca$fa8@bolivia.it.earthlink.net>
- References: <4gdr6n$6p0@guava.epix.net>
- NNTP-Posting-Host: laserlight.earthlink.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- jgvd@epix.net (Jon) wrote:
-
- >I wrote this just now and it's telling me that when i try to cout the
- >result at the bottom, it is an undefined value even though I did return
- >the result var... See if you can help.
-
- >#include <iostream.h>
-
- >float num1;
- >float num2;
-
- >getnums () {
-
- >float result = num1 +num2;
-
- >cout << "What number?\n";
- >cin >> num1;
- >cout << "And?\n";
- >cin >> num2;
-
- >return result;
- >}
-
- >main (){
-
- >getnums ();
-
-
- >cout << result;
- >}
-
- > ^^^^^^ right there is the result i want printed but it does not
- >recognize it even though I did try to return the value in the function
- >getnums... am I missing something?
-
- >Jon
-
- Assuming this is not for a school class , move
- float result = num1 +num2;
- down past where you get num1 and num2 values from cin
-
-
- cout << "What number?\n";
- cin >> num1;
- cout << "And?\n";
- cin >> num2;
- float result = num1 +num2;
- return result;
-
- Lewis
-
-